import request from "@/utils/request";
// 菜单基础URL
const MENU_BASE_URL = "/api/v1/menus";

let data = [
  {
    path: "/user",
    component: "Layout",
    redirect: "/user/studentView",
    name: "/user",
    meta: {
      title: "用户管理",
      icon: "system",
      hidden: false,
      alwaysShow: false,
      params: null,
    },
    children: [
      {
        path: "student",
        component: "user/studentView",
        name: "student",
        meta: {
          title: "学生列表",
          icon: "el-icon-User",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "studentEdit",
        component: "user/studentEditView",
        name: "studentEdit",
        meta: {
          title: "学生编辑",
          icon: "el-icon-User",
          hidden: true,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "administrator",
        component: "user/administratorView",
        name: "administrator",
        meta: {
          title: "管理员列表",
          icon: "role",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "administratorEdit",
        component: "user/administratorEditView",
        name: "administratorEdit",
        meta: {
          title: "管理员编辑",
          icon: "role",
          hidden: true,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
    ],
  },
  {
    path: "/exam",
    component: "Layout",
    redirect: "/exam/paperView",
    name: "/exam",
    meta: {
      title: "卷题管理",
      icon: "system",
      hidden: false,
      alwaysShow: false,
      params: null,
    },
    children: [
      {
        path: "paper",
        component: "exam/paperView",
        name: "paper",
        meta: {
          title: "试卷列表",
          icon: "el-icon-User",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "question",
        component: "exam/questionView",
        name: "question",
        meta: {
          title: "题目列表",
          icon: "el-icon-User",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "paperEdit",
        component: "exam/paperEditView",
        name: "paperEdit",
        meta: {
          title: "管理员列表",
          icon: "role",
          hidden: true,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "questionEdit",
        component: "exam/questionEditView",
        name: "questionEdit",
        meta: {
          title: "管理员列表",
          icon: "role",
          hidden: true,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
    ],
  },
  {
    path: "/task",
    component: "Layout",
    redirect: "/task/list",
    name: "Task",
    meta: {
      title: "任务管理",
      icon: "system",
      hidden: false,
      alwaysShow: false,
      params: null,
    },
    children: [
      {
        path: "list",
        component: "task/taskListView",
        name: "TaskList",
        meta: {
          title: "任务列表",
          icon: "el-icon-List",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "create",
        component: "task/taskCreateView",
        name: "TaskCreate",
        meta: {
          title: "任务创建",
          icon: "el-icon-Plus",
          hidden: false,
          keepAlive: false,
          alwaysShow: false,
          params: null,
        },
      },
    ],
  },
  {
    path: "/education",
    component: "Layout",
    redirect: "/education/subjectList",
    name: "Education",
    meta: {
      title: "教育管理",
      icon: "system",
      hidden: false,
      alwaysShow: true,
      params: null,
    },
    children: [
      {
        path: "subjectList",
        component: "education/subjectListView",
        name: "SubjectList",
        meta: {
          title: "学科列表",
          icon: "el-icon-Menu",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
    ],
  },
  {
    path: "/score",
    component: "Layout",
    redirect: "/score/answerSheetList",
    name: "Score",
    meta: {
      title: "成绩管理",
      icon: "system",
      hidden: false,
      alwaysShow: true,
      params: null,
    },
    children: [
      {
        path: "answerSheetList",
        component: "score/answerSheetListView",
        name: "AnswerSheetList",
        meta: {
          title: "答卷列表",
          icon: "el-icon-Document",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
    ],
  },
  {
    path: "/message",
    component: "Layout",
    redirect: "/message/list",
    name: "Message",
    meta: {
      title: "消息中心",
      icon: "el-icon-Message",
      hidden: false,
      alwaysShow: false,
      params: null,
    },
    children: [
      {
        path: "list",
        component: "message/messageListView",
        name: "MessageList",
        meta: {
          title: "消息列表",
          icon: "el-icon-List",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "send",
        component: "message/messageSendView",
        name: "MessageSend",
        meta: {
          title: "消息发送",
          icon: "el-icon-PaperPlane",
          hidden: false,
          keepAlive: false,
          alwaysShow: false,
          params: null,
        },
      },
    ],
  },
  {
    path: "/log",
    component: "Layout",
    redirect: "/log/userLog",
    name: "Log",
    meta: {
      title: "日志中心",
      icon: "el-icon-Tickets",
      hidden: false,
      alwaysShow: true,
      params: null,
    },
    children: [
      {
        path: "userLog",
        component: "log/userLogView",
        name: "UserLog",
        meta: {
          title: "用户日志",
          icon: "el-icon-User",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
    ],
  },
  // {
  //   path: "/multi-level",
  //   component: "Layout",
  //   name: "/multiLevel",
  //   meta: {
  //     title: "多级菜单",
  //     icon: "cascader",
  //     hidden: false,
  //     alwaysShow: true,
  //     params: null,
  //   },
  //   children: [
  //     {
  //       path: "multi-level1",
  //       component: "demo/multi-level/level1",
  //       name: "MultiLevel1",
  //       meta: {
  //         title: "菜单一级",
  //         icon: "",
  //         hidden: false,
  //         alwaysShow: true,
  //         params: null,
  //       },
  //       children: [
  //         {
  //           path: "multi-level2",
  //           component: "demo/multi-level/children/level2",
  //           name: "MultiLevel2",
  //           meta: {
  //             title: "菜单二级",
  //             icon: "",
  //             hidden: false,
  //             alwaysShow: false,
  //             params: null,
  //           },
  //           children: [
  //             {
  //               path: "multi-level3-1",
  //               component: "demo/multi-level/children/children/level3-1",
  //               name: "MultiLevel31",
  //               meta: {
  //                 title: "菜单三级-1",
  //                 icon: "",
  //                 hidden: false,
  //                 keepAlive: true,
  //                 alwaysShow: false,
  //                 params: null,
  //               },
  //             },
  //             {
  //               path: "multi-level3-2",
  //               component: "demo/multi-level/children/children/level3-2",
  //               name: "MultiLevel32",
  //               meta: {
  //                 title: "菜单三级-2",
  //                 icon: "",
  //                 hidden: false,
  //                 keepAlive: true,
  //                 alwaysShow: false,
  //                 params: null,
  //               },
  //             },
  //           ],
  //         },
  //       ],
  //     },
  //   ],
  // },
  // {
  //   path: "/api",
  //   component: "Layout",
  //   name: "/api",
  //   meta: {
  //     title: "接口文档",
  //     icon: "api",
  //     hidden: false,
  //     alwaysShow: true,
  //     params: null,
  //   },
  //   children: [
  //     {
  //       path: "apifox",
  //       component: "demo/api/apifox",
  //       name: "Apifox",
  //       meta: {
  //         title: "Apifox",
  //         icon: "api",
  //         hidden: false,
  //         keepAlive: true,
  //         alwaysShow: false,
  //         params: null,
  //       },
  //     },
  //   ],
  // },
  // {
  //   path: "/doc",
  //   component: "Layout",
  //   redirect: "https://juejin.cn/post/7228990409909108793",
  //   name: "/doc",
  //   meta: {
  //     title: "平台文档",
  //     icon: "document",
  //     hidden: false,
  //     alwaysShow: false,
  //     params: null,
  //   },
  //   children: [
  //     {
  //       path: "internal-doc",
  //       component: "demo/internal-doc",
  //       name: "InternalDoc",
  //       meta: {
  //         title: "平台文档(内嵌)",
  //         icon: "document",
  //         hidden: false,
  //         alwaysShow: false,
  //         params: null,
  //       },
  //     },
  //     {
  //       path: "https://juejin.cn/post/7228990409909108793",
  //       name: "Https://juejin.cn/post/7228990409909108793",
  //       meta: {
  //         title: "平台文档(外链)",
  //         icon: "el-icon-link",
  //         hidden: false,
  //         alwaysShow: false,
  //         params: null,
  //       },
  //     },
  //   ],
  // },
];

const MenuAPI = {
  /**
   * 获取当前用户的路由列表
   * <p/>
   * 无需传入角色，后端解析token获取角色自行判断是否拥有路由的权限
   *
   * @returns 路由列表
   */
  getRoutes() {
    return Promise.resolve(data);
  },

  /**
   * 获取菜单树形列表
   *
   * @param queryParams 查询参数
   * @returns 菜单树形列表
   */
  getList(queryParams: MenuQuery) {
    return request<any, MenuVO[]>({
      url: `${MENU_BASE_URL}`,
      method: "get",
      params: queryParams,
    });
  },

  /**
   * 获取菜单下拉数据源
   *
   * @returns 菜单下拉数据源
   */
  getOptions(onlyParent?: boolean) {
    return request<any, OptionType[]>({
      url: `${MENU_BASE_URL}/options`,
      method: "get",
      params: { onlyParent: onlyParent },
    });
  },

  /**
   * 获取菜单表单数据
   *
   * @param id 菜单ID
   */
  getFormData(id: string) {
    return request<any, MenuForm>({
      url: `${MENU_BASE_URL}/${id}/form`,
      method: "get",
    });
  },

  /**
   * 添加菜单
   *
   * @param data 菜单表单数据
   * @returns 请求结果
   */
  create(data: MenuForm) {
    return request({
      url: `${MENU_BASE_URL}`,
      method: "post",
      data: data,
    });
  },

  /**
   * 修改菜单
   *
   * @param id 菜单ID
   * @param data 菜单表单数据
   * @returns 请求结果
   */
  update(id: string, data: MenuForm) {
    return request({
      url: `${MENU_BASE_URL}/${id}`,
      method: "put",
      data: data,
    });
  },

  /**
   * 删除菜单
   *
   * @param id 菜单ID
   * @returns 请求结果
   */
  deleteById(id: string) {
    return request({
      url: `${MENU_BASE_URL}/${id}`,
      method: "delete",
    });
  },
};

export default MenuAPI;

/** 菜单查询参数 */
export interface MenuQuery {
  /** 搜索关键字 */
  keywords?: string;
}

/** 菜单视图对象 */
export interface MenuVO {
  /** 子菜单 */
  children?: MenuVO[];
  /** 组件路径 */
  component?: string;
  /** ICON */
  icon?: string;
  /** 菜单ID */
  id?: string;
  /** 菜单名称 */
  name?: string;
  /** 父菜单ID */
  parentId?: string;
  /** 按钮权限标识 */
  perm?: string;
  /** 跳转路径 */
  redirect?: string;
  /** 路由名称 */
  routeName?: string;
  /** 路由相对路径 */
  routePath?: string;
  /** 菜单排序(数字越小排名越靠前) */
  sort?: number;
  /** 菜单 */
  type?: number;
  /** 菜单是否可见(1:显示;0:隐藏) */
  visible?: number;
}

/** 菜单表单对象 */
export interface MenuForm {
  /** 菜单ID */
  id?: string;
  /** 父菜单ID */
  parentId?: string;
  /** 菜单名称 */
  name?: string;
  /** 菜单是否可见(1-是 0-否) */
  visible: number;
  /** ICON */
  icon?: string;
  /** 排序 */
  sort?: number;
  /** 路由名称 */
  routeName?: string;
  /** 路由路径 */
  routePath?: string;
  /** 组件路径 */
  component?: string;
  /** 跳转路由路径 */
  redirect?: string;
  /** 菜单 */
  type?: number;
  /** 权限标识 */
  perm?: string;
  /** 【菜单】是否开启页面缓存 */
  keepAlive?: number;
  /** 【目录】只有一个子路由是否始终显示 */
  alwaysShow?: number;
  /** 参数 */
  params?: KeyValue[];
}

interface KeyValue {
  key: string;
  value: string;
}

/** RouteVO，路由对象 */
export interface RouteVO {
  /** 子路由列表 */
  children: RouteVO[];
  /** 组件路径 */
  component?: string;
  /** 路由属性 */
  meta?: Meta;
  /** 路由名称 */
  name?: string;
  /** 路由路径 */
  path?: string;
  /** 跳转链接 */
  redirect?: string;
}

/** Meta，路由属性 */
export interface Meta {
  /** 【目录】只有一个子路由是否始终显示 */
  alwaysShow?: boolean;
  /** 是否隐藏(true-是 false-否) */
  hidden?: boolean;
  /** ICON */
  icon?: string;
  /** 【菜单】是否开启页面缓存 */
  keepAlive?: boolean;
  /** 路由title */
  title?: string;
}
